﻿namespace ResumableDownload.View.Converters
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;
    using WP7Contrib.Services.DownloadManager;

    public sealed class StateToStatusConverter : IValueConverter
    {
        public readonly string StatusFormat = "Status: {0}";

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || value == DependencyProperty.UnsetValue)
            {
                return string.Format(StatusFormat, "Unknown");
            }
            
            if ((DownloaderState)value == DownloaderState.Initialising)
            {
                return string.Format(StatusFormat, "Initialising download manager...");
            }

            if ((DownloaderState)value == DownloaderState.Ready)
            {
                return string.Format(StatusFormat, "Ready to start...");
            }

            if ((DownloaderState)value == DownloaderState.Processing)
            {
                return string.Format(StatusFormat, "Processing...");
            }

            if ((DownloaderState)value == DownloaderState.PausedWaiting)
            {
                return string.Format(StatusFormat, "Waiting for download...");
            }

            if ((DownloaderState)value == DownloaderState.PausedNetwork)
            {
                return string.Format(StatusFormat, "Waiting for network connectivity...");
            }

            if ((DownloaderState)value == DownloaderState.Starting)
            {
                return string.Format(StatusFormat, "Starting up...");
            }

            if ((DownloaderState)value == DownloaderState.Stopping)
            {
                return string.Format(StatusFormat, "Shutting down...");
            }

            return string.Format(StatusFormat, "Unknown...");
        }
        
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DependencyProperty.UnsetValue;
        }
    }
}
